<template>
	<div class="child">
		<h3>子组件</h3>
		<h4>玩具：{{ toy }}</h4>
		<!-- 触发 send-boy 事件  -->
		<button @click="emit('send-toy', toy)">发送toy 测试</button>
		<button @click="emit('send-name',name)"> 发送 name 测试</button>
	</div>
</template>

<script setup lang="ts" name="Child">
import { ref, onMounted } from "vue";

// 数据
let toy = ref('奥特曼')

let name = ref('frank')

// 声明事件
const emit = defineEmits(['send-toy', 'send-name'])

// 触发实现
// emit('send-toy')


let  toys = [
  "乐高积木 (Lego Bricks)",
  "磁力片 (Magnetic Tiles)",
  "拼图 (Jigsaw Puzzles)",
  "多米诺骨牌 (Dominoes)",
  "华容道/孔明锁 (Sliding Block Puzzles / Burr Puzzles)",
  "鲁班锁 (Lu Ban Lock)",
  "俄罗斯方块积木 (Tetris Blocks)",
  "齿轮积木 (Gear Building Sets)",
]
//挂载3s之后触发事件
onMounted(() => {
	let randomIndex = Math.floor(Math.random() * toys.length)
	toy.value = toys[randomIndex]
	// console.log('child Mounted, 2s 触发 send-boy 事件')
	// setTimeout(() => {
	// 	emit('send-toy')
	// }, 2000)
})
</script>

<style scoped>
.child {
	margin-top: 20px;
	background-color: rgb(76, 209, 76);
	padding: 10px;
	box-shadow: 0 0 10px black;
	border-radius: 10px;
}

.child button {
	margin-right: 8px;
	padding: 8px ;
	border-radius: 8px;
}
</style>